\documentclass[a4paper]{article}
\usepackage[affil-it]{authblk}
\usepackage[backend=bibtex,style=numeric]{biblatex}
\usepackage{amsmath}  
\usepackage{indentfirst}
\usepackage{geometry}
\usepackage{amsthm}
\usepackage{titlesec}  
\newtheorem*{acknowledgements}{Acknowledgements} 
\usepackage{multirow}
\BeforeBeginEnvironment{abstract}{\vspace{-25pt}}  
\titlespacing{\section}{0pt}{\parskip}{-\parskip}  
\geometry{margin=1.5cm, vmargin={0pt,1cm}}
\setlength{\topmargin}{-1cm}
\setlength{\paperheight}{29.7cm}
\setlength{\textheight}{25.3cm}

\addbibresource{citation.bib}

\begin{document}
% =================================================
\title{Numerical Analysis report1}

\author{YanYuqing 3220104804
  \thanks{Electronic address:\texttt{3220104804@zju.edu.cn}}}
\affil{statistics 2201, Zhejiang University }


\date{}

\maketitle

\begin{abstract}  
In this programming assignment, we implemented the three root-finding methods from the first chapter using C++. In Problem A, we defined three classes corresponding to these methods. Problems B, C, and D provide examples of applying these three methods for solving specific cases. Problems E and F demonstrate the application of the defined root-finding methods to solve real-world problems.
\end{abstract} 

\section*{Problem A}
To begin with, in order to define the abstract base class \texttt{EquationSolver} and the pure virtual function \texttt{solve}, we need to consider the way in which the function F is passed. To achieve this, we have defined an abstract function class, \texttt{Function}, along with methods for computing values and derivatives. This allows the base class \texttt{EquationSolver}  to compute the solutions of the equation using F as an object.

In specific methods, we have employed the classic inheritance operation in C++, while defining the specific implementation of solve in each method. This has resulted in the formation of classes for different methods.

\section*{Problem B}
The results and errors of the bisection method for four equations are:
\begin{center}
    \begin{tabular}{|c|c|c|}  
    \hline  
    Function & Solution & Error \\  
    \hline  
    $x^{-1}-\tan x \ on \ [0,\frac{\pi}{2}]$ & 0.860334
 & $-2.23\times 10^{-7}$  \\  
    \hline  
    $x^{-1}-2^x \ on \ [0,1]$ & 0.641186
 & $-5.62\times 10^{-8}$  \\  
    \hline  
     $2^{-x} +e^x+2\cos x-6 \ on \ [1,3]$ & 1.82938
 & $-4.49\times 10^{-7}$  \\
    \hline  
     $\dfrac{x^3+4x^2+3x+5}{2x^3-9x^2+18x-2} \ on \ [0,4]$ & 0.117877
 & $-9.14\times 10^{6}$  \\
    \hline  
\end{tabular}  
\end{center}

The solutions and errors of the first three equations are as expected, but the error of the fourth solution tells us that it is evidently incorrect. Why does this situation occur? In fact, upon observation, it can be noted that the numerator of the fourth function is always greater than 0 over the given bisection interval. Therefore, the equation has no solution, and the termination reason is actually reaching the maximum iteration count, resulting in the output not being a solution to the equation.

\section*{Problem C}
The results and errors of the Newton method for $x=\tan x$ with initial values 4.5 and 7.7 are:

\begin{center}
    \begin{tabular}{|c|c|c|c|}  

\hline  
Function & Initial Values & Solution & Error \\
\hline 
\multirow{2}{*}{$x-tanx$} & 4.5 &  4.49341 & $-3.69\times 10^{-12}$\\  
\cline{2-4}
& 7.7 &  7.72525 & $-4.51\times 10^{-11}$\\    

\hline  
\end{tabular}
\end{center}

The solutions and errors are as expected.

\section*{Problem D}
The results and errors of the Secant method for three equations are:
\begin{center}
\begin{tabular}{|c|c|c|c|}  
\hline  
Function & Initial Values & Solution & Error \\
\hline 
\multirow{2}{*}{$sin(\frac{x}{2})-1$} & $x_0=0,x_1=\frac{\pi}{2}$ &  3.14093 & $-5.45\times 10^{-8}$\\  
\cline{2-4}
& $x_0=0,x_1=\frac{\pi}{3}$ &  3.14082 & $-7.38\times 10^{-8}$\\    
\hline  
\multirow{2}{*}{$e^x-\tan x$} & $x_0=1,x_1=1.4$ &  1.30633 & $-6.52\times 10^{-12}$\\  
\cline{2-4}
& $x_0=0.5,x_1=1$ &  -153.938 & $8.16\times 10^{-11}$\\    
\hline  
\multirow{2}{*}{$x^3-12x^2+3x+1$} & $x_0=0,x_1=-0.5$ &  -0.188685 & $-6.32\times 10^{-9}$\\  
\cline{2-4}
& $x_0=0.5,x_1=0$ &  0.451543 & $6.57\times 10^{-8}$\\    
\hline  
\end{tabular}
\end{center}

Clearly, in terms of the error, the solutions iterated from each initial value are valid approximate solutions, but the solutions from the initial values of equations 2 and 3 differ significantly and are not the same.

\section*{Problem E}
The problem requires solving an equation using three methods. Since the latter two methods involve the selection of initial values, especially the Newton’s method which requires an approximate solution close to the real solution, we first run the program for the bisection method in the interval [-1, 1] to find an approximate solution for the equation. Subsequently, we select values near this solution as initial values for the latter two methods. The results of the runs are as follows:
\begin{center}
    \begin{tabular}{|c|c|c|c|c|}  
    \hline  
    Function & Methods & Initial Values(Intervals) & Solutions & Errors \\  
    \hline  
    \multirow{3}{*}{$10(0.5\pi-\arcsin(x)-x\sqrt{1-x^2}-12.4)$} & Bisection method
 & [-1,1] &  0.17 & $4.06\times 10^{-6}$\\  
    \cline{2-5}
    & Newton’s method & 0.2 & 0.17
 & $2.12\times 10^{-8}$  \\  
    \cline{2-5}
     & Secant Method & $x_0=0,x_1=0.5$
 & 0.17 & $-1.12\times 10^{-10}$  \\
    
    \hline  
\end{tabular}  
\end{center}

To an accuracy of 0.01, the solutions obtained by these three methods are both 0.17. However, in terms of the error, the solution from the secant method is the most accurate, followed by the Newton’s method, and the solution from the bisection method is the least accurate.

\section*{Problem F}
In this problem, we want to solve the equation \begin{equation}
A\sin\alpha \cos\alpha +B\sin^2\alpha -C\cos\alpha -E\sin\alpha =0
\end{equation}

where $$A=l\sin\beta_1,B=l\cos\beta_1,C=(h+0.5D)\sin\beta_1-0.5D\tan\beta_1,E=(h+0.5D)\cos\beta_1-0.5D$$ 
\subsection*{F(a)}
The results are as follows:
\begin{center}
    \begin{tabular}{|c|c|c|c|}  
    \hline  
    Function &  Initial Values & Solution & Error \\  
    \hline  
    (1) & $l=89,h=49,D=55,\beta=11.5^\circ,x_0=33^\circ$ &  $32.9722^\circ$ & $9.66\times 10^{-13}$\\  
    \hline  
\end{tabular}  
\end{center}

\subsection*{F(b)}
The results are as follows:
\begin{center}
    \begin{tabular}{|c|c|c|c|}  
    \hline  
    Function &  Initial Values & Solution & Error \\  
    \hline  
    (1) & $l=89,h=49,D=30,\beta=11.5^\circ ,x_0=33^\circ $ &  $33.1689^\circ $ & $1.30\times 10^{-9}$\\  
    \hline  
\end{tabular}  
\end{center}

\subsection*{F(c)}
The results are as follows:
\begin{center}
    \begin{tabular}{|c|c|c|c|}  
    \hline  
    Function &  Initial Values & Solutions & Errors\\  
    \hline  
    \multirow{3}{*}{(1)} & $l=89,h=49,D=55,\beta=11.5^\circ ,x_0=33^\circ ,x_1=45^\circ $ &  $32.9722^\circ $ & $6.56\times 10^{-9}$\\  
    \cline{2-4} 
    & $l=89,h=49,D=55,\beta=11.5^\circ ,x_0=33^\circ ,x_1=90^\circ $ &  $32.9722^\circ $ & $-8.27\times 10^{-12}$\\  
    \cline{2-4}
    & $l=89,h=49,D=55,\beta=11.5^\circ ,x_0=33^\circ ,x_1=348.6^\circ $ &  $348.5^\circ $ & $-3.00\times 10^{-9}$\\  
    \hline  
\end{tabular}  
\end{center}

How do we explain the last solution obtained by the secant method reaching $348.5^\circ$? In fact, for the selection of the second initial value, we intentionally chose a value very close to this solution. This is because through observation of the equation, we can find that $\alpha=-\beta$ is an analytical solution of the equation. By considering the periodicity, we immediately obtain that $348.5^\circ$ is a precise solution of the equation.

\begin{acknowledgements}  

At the end of this report, I must express my sincere gratitude to my roommate Peng Haowei. Firstly, he taught me how to write a Makefile. Secondly, in the third sub-question of problem F, he pointed out the possibility of an analytical solution $\alpha=-\beta$ to the equation by obtaining a different solution from running my code, and provided a reasonable explanation for the existence of this solution. But for his help, I wouldn't submit a satisfactory assignment. Thanks a lot for his help.

\end{acknowledgements}

\end{document}